package com.bestcem.xm.om.dao.impl;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.om.dao.EmailBoxDao;
import com.bestcem.xm.om.dao.mapper.EmailBoxMapper;
import com.bestcem.xm.om.entity.EmailBox;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zq.ding <zq.ding@idiaoyan.com>
 * @version v1.0
 * @date 2021/11/18 13:31
 */
@Repository
public class EmailBoxDaoImpl implements EmailBoxDao {
    @Resource
    private EmailBoxMapper emailBoxMapper;

    @Override
    public EmailBox save(EmailBox emailBox) {
        if (!ObjectId.isValid(emailBox.getId())) {
            emailBox.setId(ObjectId.next());
        }
        emailBoxMapper.save(emailBox);
        return emailBox;
    }

    @Override
    public Boolean deleteByAccount(String account) {
        emailBoxMapper.deleteByAccount(account);
        return true;
    }

    @Override
    public List<EmailBox> listMailBoxes() {
        return emailBoxMapper.listMailBoxes();
    }

    @Override
    public EmailBox findByAccount(String account) {
        return emailBoxMapper.findByAccount(account);
    }

    @Override
    public void update(EmailBox emailBox) {
        emailBoxMapper.update(emailBox);
    }
}
